/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.fl.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.fl.entity.Evaluate;
import com.jeesite.modules.fl.service.EvaluateService;

/**
 * 评价表Controller
 * @author anthony
 * @version 2019-01-08
 */
@Controller
@RequestMapping(value = "${adminPath}/fl/evaluate")
public class EvaluateController extends BaseController {

	@Autowired
	private EvaluateService evaluateService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public Evaluate get(String id, boolean isNewRecord) {
		return evaluateService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("fl:evaluate:view")
	@RequestMapping(value = {"list", ""})
	public String list(Evaluate evaluate, Model model) {
		model.addAttribute("evaluate", evaluate);
		return "modules/fl/evaluateList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("fl:evaluate:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<Evaluate> listData(Evaluate evaluate, HttpServletRequest request, HttpServletResponse response) {
		Page<Evaluate> page = evaluateService.findPage(new Page<Evaluate>(request, response), evaluate); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("fl:evaluate:view")
	@RequestMapping(value = "form")
	public String form(Evaluate evaluate, Model model) {
		model.addAttribute("evaluate", evaluate);
		return "modules/fl/evaluateForm";
	}

	/**
	 * 保存评价表
	 */
	@RequiresPermissions("fl:evaluate:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated Evaluate evaluate) {
		evaluateService.save(evaluate);
		return renderResult(Global.TRUE, text("保存评价表成功！"));
	}
}